package com.lemon.exam.common.config;

import com.lemon.exam.common.properties.Knife4jOpenApiProperties;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;

/**
 * Knife4j 配置类
 *
 * @author Lemon
 * @since 2025/3/24 11:47
 */
@Configuration
@AutoConfigureAfter(Knife4jOpenApiProperties.class)
public class Knife4jConfiguration {

    /**
     * knife4j配置
     *
     * @return
     */
    @Bean
    public OpenAPI openAPI(Knife4jOpenApiProperties knife4jOpenApiProperties) {
        return new OpenAPI()
                .info(knife4jOpenApiProperties.getInfo())
                .addSecurityItem(new SecurityRequirement().addList("JWT"))
                .schemaRequirement("JWT", new SecurityScheme()
                        .name(HttpHeaders.AUTHORIZATION)
                        .type(SecurityScheme.Type.APIKEY)
                        .in(SecurityScheme.In.HEADER)
                        .description("JWT 认证 Token"));
    }

}
